#define DEBUG
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>

using namespace std;

typedef long long ll;
const int maxn=100000;

class Hash {
public:
  const static int size=141517;
  ll k[size];
  stack<int> v[size];

  void push(ll key, int val) {
    int p=key%size;
    for (; k[p]; p=(p+1)%size) {
      if (k[p]==key) {
        break;
      }
    }
    k[p] = key;
    v[p].push(val);
  }

  int get(ll key, int def=0) {
    int p=key%size, ret=def;
    for (; k[p]; p=(p+1)%size) {
      if (k[p]==key) {
        if (!v[p].empty()) {
          ret = v[p].top();
          v[p].pop();
          break;
        }
      }
    }
    return ret;
  }
};

bool cmp(int *a, int *b) {
  return *a<*b;
}

void divide(int n, int a[], int block[], int ran[][2]) {
  int *p[maxn+1];
  for (int i=1; i<=n; i++) {
    ran[i][0] = n+1;
    p[i] = a+i;
  }
  sort(p+1, p+n+1, cmp);

  int last=*p[1];
  block[0] = 1;
  for (int i=1; i<=n; i++) {
    if (*p[i]==last) *p[i]=block[i]=block[i-1];
    else {
      last = *p[i];
      *p[i] = block[i] = block[i-1]+1;
    }
    ran[block[i]][0] = min(ran[block[i]][0], i);
    ran[block[i]][1] = max(ran[block[i]][1], i);
  }
}

int main() {
#ifdef DEBUG
  freopen("src.in", "r", stdin);
  freopen("src.out", "w", stdout);
#endif

  static int a[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", a+i);
  }

  int tag=0;
  for (int i=1; !tag && i<n; i++) {
    if (a[i]>a[i+1]) tag=1;
  }
  if (tag==0) printf("%d\n", tag);

  static int blo[maxn+1], ran[maxn+1][2], ans[maxn+1][2];
  static bool vis[maxn+1];
  static Hash hash;
  divide(n, a, blo, ran);
  for (int i=1; i<=n; i++) {
    hash.push((ll)blo[i]*(maxn+1)+a[i], i);
  }
  for (int i=1; i<=n && tag==1; i++) {
    if (!vis[i] && a[i]!=blo[i]) {
      vis[i] = true;
      int t=hash.get((ll)a[i]*(maxn+1)+blo[i]);
      if (t) {
        ans[++ans[0][0]][0] = i;
        ans[ans[0][0]][1] = t;
        vis[t] = true;
      } else tag++;
    }
  }
  if (tag==1) {
    printf("1\n%d ", ans[0][0]);
    for (int i=1; i<=ans[0][0]; i++) {
      printf("%d %d ", ans[i][0], ans[i][1]);
    }
    return 0;
  }

  static int ans2[maxn+1][2], cir[maxn+1], ind[maxn+1];
  memset(vis, 0, sizeof vis);
  ans[0][0] = 0;
  for (int i=1; i<=blo[n]; i++) {
    ind[i] = ran[i][0];
  }
  for (int i=1; i<=n; i++) {
    if (!vis[i] && a[i]!=blo[i]) {
      vis[i] = true;
      cir[0] = 1;
      cir[1] = i;
      int t;
      for (t=ind[a[i]]; blo[t]!=blo[i]; t=ind[a[t]]) {
        for (; a[t]==blo[t]; t++);
        vis[t] = true;
        ind[blo[t]] = t+1;
        cir[++cir[0]] = t;
      }
      ans[++ans[0][0]][0] = cir[cir[0]];
      ans[ans[0][0]][1] = cir[cir[0]-1];
      for (int i=1, j=cir[0]-2; i<j; i++, j--) {
        ans[++ans[0][0]][0] = cir[i];
        ans[ans[0][0]][1] = cir[j];
      }

      for (int i=1, j=cir[0]-1; i<j; i++, j--) {
        ans2[++ans2[0][0]][0] = cir[i];
        ans2[ans2[0][0]][1] = cir[j];
      }
    }
  }
  printf("2\n%d ", ans[0][0]);
  for (int i=1; i<=ans[0][0]; i++) {
    printf("%d %d ", ans[i][0], ans[i][1]);
  }
  printf("\n%d ", ans2[0][0]);
  for (int i=1; i<=ans2[0][0]; i++) {
    printf("%d %d ", ans2[i][0], ans2[i][1]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
